//============================================================================
// Name        : t_scheduler.cpp
// Author      : inkooboo
// Version     :
// Copyright   :
// Description : main in C++
//============================================================================

#include "systems/scheduler.hpp"
#include "systems/logger.hpp"

#include <boost/bind.hpp>


using namespace std;

struct printer_t {
  printer_t() : counter(0) {}
  void handler() {
    boost::mutex::scoped_lock g(guard);
    logger::log(DEBUG) << "fire " << counter++;
  }

  boost::mutex guard;
  int counter;
} printer;

int main(void) {

  scheduler_t::get_singleton().start(3);


  const static long count = 10;

  logger::log(DEBUG) << "wait " << count << " sec, scheduling";

  handler_t handler = boost::bind(&printer_t::handler, boost::ref(printer));
  for (long i = 0; i< count; ++i ) {
    boost::posix_time::time_duration td = boost::posix_time::seconds(count - i);
    scheduler_t::get_singleton().set_timer(handler, td);
    boost::this_thread::sleep(boost::posix_time::seconds(1));
  }

  cin.get();

  scheduler_t::get_singleton().stop();

  return 0;
}
